﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JSON;
using Facebook_Graph_Toolkit.FacebookObjects;

namespace Facebook_Graph_Toolkit.GraphApi {
    /// <summary>
    /// Represents a Notification in Facebook
    /// </summary>
    public class Notification : GraphApiObject{
        internal Notification(JsonObject JO) : base(JO) { }
        /// <summary>
        /// Gets information of a Notification
        /// </summary>
        /// <param name="NotificationID"></param>
        /// <param name="AccessToken"></param>
        public Notification(string NotificationID, string AccessToken) : base(Helpers.WebResponseHelper.GetJsonFromFacebookObject(NotificationID, AccessToken)) { }
        /// <summary>
        /// The ID of the Notification
        /// </summary>
        public string ID { get { return (string)data["id"]; } }
        /// <summary>
        /// The person or profile whose action created this Notification
        /// </summary>
        public NameIDPair Sender { get { return new NameIDPair((JsonObject)data["from"]); } }
        /// <summary>
        /// The person to be notified
        /// </summary>
        public NameIDPair Receiver { get { return new NameIDPair((JsonObject)data["to"]); } }
        /// <summary>
        /// The time which this Notification was created
        /// </summary>
        public DateTime CreatedTime {
            get {
                return Helpers.Common.RFC3339ToDateTime((string)data["created_time"]);
            }
        }
        /// <summary>
        /// The time which this Notification was updated
        /// </summary>
        public DateTime UpdatedTime {
            get {
                return Helpers.Common.RFC3339ToDateTime((string)data["updated_time"]);
            }
        }
        /// <summary>
        /// The title of this Notification
        /// </summary>
        public string Title { get { return (string)data["title"]; } }
        /// <summary>
        /// The message in this Notification (usually null)
        /// </summary>
        public string Message { get { return (string)data["message"]; } }
        /// <summary>
        /// Whether this notification has not been read by the user
        /// </summary>
        public bool Unread {
            get {
                if ((int)data["unread"] == 0) return false;
                if ((int)data["unread"] == 1) return true;
                throw new FacebookException("Unknown value returned by Facebook in [unread] field");
            }
        }
        /// <summary>
        /// The URL to the Nofitication story on Facebook
        /// </summary>
        public string Link { get { return (string)data["link"]; } }
        /// <summary>
        /// The application that created this Notification
        /// </summary>
        public NameIDPair Application { get { return new NameIDPair((JsonObject)data["application"]); } }
    }
}
